Library & Dataset

Using OLR

Inspect Dataset Using Training and Validation

OLR Equations

Inspect Dataset Using Training and Validation

vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage , data=train.data)

# took out density since training has 0 d4 and it was not allowing do the plot

p <- plot(vclust)

par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)

#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito +  TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana 

Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)

#library(plyr)
brick <- count(train.data$brick) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "brick")

wood <- count(train.data$wood) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wood")

mixed <- count(train.data$mixed) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "mixed")

TC_mature_soil <- count(train.data$TC_mature_soil) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_mature_soil")

T_construction  <- count(train.data$T_construction ) %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "T_construction ")

spring <- count(train.data$spring) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "spring")

landfill <- count(train.data$landfill) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "landfill")

garbage <- count(train.data$garbage) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "garbage")

crack <- count(train.data$crack) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "crack")

leaning_wall <- count(train.data$leaning_wall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "leaning_wall")

scars <- count(train.data$scars) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "DepTaludeAterro")

downward_floor <- count(train.data$downward_floor) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "scars")

tilted <- count(train.data$tilted) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tilted")

conc_rainfall <- count(train.data$conc_rainfall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall")

wastewater <- count(train.data$wastewater) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wastewater")

leak <- count(train.data$leak) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall_water")

septic_tank <- count(train.data$septic_tank) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "septic_tank")

angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
  mutate("Percentage"=(freq/106)*100)%>%
  mutate("Classifier" = "angle")

EN <- count(train.data$EN) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "EN")

TC <- count(train.data$TC)  %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "TC")

TC_saprolite_soil  <- count(train.data$TC_saprolite_soil )  %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_saprolite_soil ")

banana <- count(train.data$banana) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "banana")

drainage <- count(train.data$drainage) %>%
  mutate ("Percentage"=(freq/176.7)*100)%>%
  mutate("Classifier" = "drainage")

deforestation <- count(train.data$deforestation) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "deforestation")

TC_unstable_structure  <- count(train.data$TC_unstable_structure ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_unstable_structure ")


tree <- count(train.data$tree) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tree")

ground_veg <- count(train.data$ground_veg) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "ground_veg")


density <- count(train.data$density)  %>% #(79, 415, 36) # d4 =0 
  mutate ("Percentage"=(freq/132.5)*100)%>%
  mutate("Classifier" = "density")

TC_weath_rock  <- count(train.data$TC_weath_rock ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_weath_rock ")

fracture <- count(train.data$fracture) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "fracture")









df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil,  banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)

df
##        x freq  Percentage             Classifier
## 1  FALSE   37  13.9622642                  brick
## 2   TRUE  493 186.0377358                  brick
## 3  FALSE  456 172.0754717                   wood
## 4   TRUE   74  27.9245283                   wood
## 5  FALSE  489 184.5283019                  mixed
## 6   TRUE   41  15.4716981                  mixed
## 7  FALSE  252  95.0943396         TC_mature_soil
## 8   TRUE  278 104.9056604         TC_mature_soil
## 9  FALSE  207  78.1132075        T_construction 
## 10  TRUE  323 121.8867925        T_construction 
## 11 FALSE  509 192.0754717                 spring
## 12  TRUE   21   7.9245283                 spring
## 13 FALSE  329 124.1509434               landfill
## 14  TRUE  201  75.8490566               landfill
## 15 FALSE  348 131.3207547                garbage
## 16  TRUE  182  68.6792453                garbage
## 17 FALSE  441 166.4150943                  crack
## 18  TRUE   89  33.5849057                  crack
## 19 FALSE  501 189.0566038           leaning_wall
## 20  TRUE   29  10.9433962           leaning_wall
## 21 FALSE  326 123.0188679        DepTaludeAterro
## 22  TRUE  204  76.9811321        DepTaludeAterro
## 23 FALSE  462 174.3396226                  scars
## 24  TRUE   68  25.6603774                  scars
## 25 FALSE  428 161.5094340                 tilted
## 26  TRUE  102  38.4905660                 tilted
## 27 FALSE   18   6.7924528          conc_rainfall
## 28  TRUE  512 193.2075472          conc_rainfall
## 29 FALSE  200  75.4716981             wastewater
## 30  TRUE  330 124.5283019             wastewater
## 31 FALSE  336 126.7924528    conc_rainfall_water
## 32  TRUE  194  73.2075472    conc_rainfall_water
## 33 FALSE  525 198.1132075            septic_tank
## 34  TRUE    5   1.8867925            septic_tank
## 35     C   35  33.0188679                  angle
## 36     D  128 120.7547170                  angle
## 37     E  367 346.2264151                  angle
## 38 FALSE  344 129.8113208                     EN
## 39  TRUE  186  70.1886792                     EN
## 40 FALSE   28  10.5660377                     TC
## 41  TRUE  502 189.4339623                     TC
## 42 FALSE  446 168.3018868     TC_saprolite_soil 
## 43  TRUE   84  31.6981132     TC_saprolite_soil 
## 44 FALSE  355 133.9622642                 banana
## 45  TRUE  175  66.0377358                 banana
## 46     Y   63  35.6536503               drainage
## 47     P  243 137.5212224               drainage
## 48     N  224 126.7685342               drainage
## 49 FALSE  498 187.9245283          deforestation
## 50  TRUE   32  12.0754717          deforestation
## 51 FALSE  516 194.7169811 TC_unstable_structure 
## 52  TRUE   14   5.2830189 TC_unstable_structure 
## 53 FALSE  203  76.6037736                   tree
## 54  TRUE  327 123.3962264                   tree
## 55 FALSE  154  58.1132075             ground_veg
## 56  TRUE  376 141.8867925             ground_veg
## 57    d1   68  51.3207547                density
## 58    d2  425 320.7547170                density
## 59    d3   37  27.9245283                density
## 60 FALSE  519 195.8490566         TC_weath_rock 
## 61  TRUE   11   4.1509434         TC_weath_rock 
## 62 FALSE  529 199.6226415               fracture
## 63  TRUE    1   0.3773585               fracture

TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock

Equation 1

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)

# Equation 1

eq_OLR_01 <- polr(risk ~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))



p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                             Value Std. Error    t value      p value
## brickTRUE             -0.59105325  0.4451122 -1.3278748 9.210973e-02
## woodTRUE               1.00470094  0.3432157  2.9273161 1.709506e-03
## ENTRUE                 0.86440575  0.3842449  2.2496217 1.223649e-02
## TC_mature_soilTRUE     0.80236890  0.2272186  3.5312637 2.067896e-04
## T_constructionTRUE     0.30982524  0.3682327  0.8413843 2.000663e-01
## springTRUE            -0.55986054  0.5762272 -0.9715968 1.656256e-01
## landfillTRUE           0.11942449  0.3282493  0.3638226 3.579953e-01
## leakTRUE              -0.06685435  0.2309844 -0.2894323 3.861253e-01
## garbageTRUE           -0.16306467  0.2962141 -0.5504960 2.909896e-01
## crackTRUE              1.88777942  0.3280415  5.7546966 4.339876e-09
## leaning_wallTRUE       1.49165415  0.5362686  2.7815429 2.705059e-03
## scarsTRUE              3.73175588  0.3634237 10.2683346 4.893985e-25
## downward_floorTRUE     1.17538119  0.3549593  3.3113126 4.642971e-04
## tiltedTRUE             1.16533710  0.3124282  3.7299363 9.576410e-05
## septic_tankTRUE        0.41140123  1.0630605  0.3869970 3.493792e-01
## conc_rainfallTRUE      1.52144121  0.5360700  2.8381393 2.268869e-03
## wastewaterTRUE         0.82069178  0.2362695  3.4735402 2.568202e-04
## ground_vegTRUE         0.98836656  0.2596095  3.8071277 7.029507e-05
## angleD                 0.92763711  0.4542142  2.0422899 2.056139e-02
## angleE                 1.20893068  0.5357119  2.2566806 1.201402e-02
## TC_saprolite_soilTRUE  0.36070811  0.2947684  1.2237000 1.105327e-01
## R1|R2                  1.72364940  0.8749261  1.9700514 2.441624e-02
## R2|R3                  5.95423773  0.9362011  6.3599989 1.008776e-10
## R3|R4                 11.13817103  1.0614334 10.4935182 4.625893e-26
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ======================================================
##                       Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE             -0.59    0.45     -1.33   0.09  
## woodTRUE              1.00     0.34     2.93    0.002 
## ENTRUE                0.86     0.38     2.25    0.01  
## TC_mature_soilTRUE    0.80     0.23     3.53   0.0002 
## T_constructionTRUE    0.31     0.37     0.84    0.20  
## springTRUE            -0.56    0.58     -0.97   0.17  
## landfillTRUE          0.12     0.33     0.36    0.36  
## leakTRUE              -0.07    0.23     -0.29   0.39  
## garbageTRUE           -0.16    0.30     -0.55   0.29  
## crackTRUE             1.89     0.33     5.75      0   
## leaning_wallTRUE      1.49     0.54     2.78    0.003 
## scarsTRUE             3.73     0.36     10.27     0   
## downward_floorTRUE    1.18     0.35     3.31   0.0005 
## tiltedTRUE            1.17     0.31     3.73   0.0001 
## septic_tankTRUE       0.41     1.06     0.39    0.35  
## conc_rainfallTRUE     1.52     0.54     2.84    0.002 
## wastewaterTRUE        0.82     0.24     3.47   0.0003 
## ground_vegTRUE        0.99     0.26     3.81   0.0001 
## angleD                0.93     0.45     2.04    0.02  
## angleE                1.21     0.54     2.26    0.01  
## TC_saprolite_soilTRUE 0.36     0.29     1.22    0.11  
## R1| R2                1.72     0.87     1.97    0.02  
## R2| R3                5.95     0.94     6.36      0   
## R3| R4                11.14    1.06     10.49     0   
## ------------------------------------------------------

less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)

par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)

Creating function with four level

Equation 1

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+-----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4       |
## +-----------------+---+---+----+----------+------------+-----------+
## |brick            |No | 37|Inf | 2.8622009| 1.287854288|-0.86020127|
## |                 |Yes|492|Inf | 2.2958961|-0.089490571|-2.03229476|
## +-----------------+---+---+----+----------+------------+-----------+
## |wood             |No |455|Inf | 2.2344036|-0.171850257|-2.25982323|
## |                 |Yes| 74|Inf | 3.1640676| 1.134979933|-0.67294447|
## +-----------------+---+---+----+----------+------------+-----------+
## |EN               |No |343|Inf | 1.8402119|-0.518607764|-2.38209716|
## |                 |Yes|186|Inf |       Inf| 1.000631880|-1.32687094|
## +-----------------+---+---+----+----------+------------+-----------+
## |TC_mature_soil   |No |252|Inf | 1.8245493|-0.287682072|-2.25129180|
## |                 |Yes|277|Inf | 3.0948232| 0.254065462|-1.66684882|
## +-----------------+---+---+----+----------+------------+-----------+
## |T_construction   |No |207|Inf | 1.5581446|-0.896088025|-2.98061864|
## |                 |Yes|322|Inf | 3.3418976| 0.547435369|-1.51550609|
## +-----------------+---+---+----+----------+------------+-----------+
## |spring           |No |508|Inf | 2.2832504|-0.047252885|-2.04880457|
## |                 |Yes| 21|Inf |       Inf| 1.163150810|-0.09531018|
## +-----------------+---+---+----+----------+------------+-----------+
## |landfill         |No |328|Inf | 1.8387844|-0.523855124|-2.53897387|
## |                 |Yes|201|Inf | 4.6001576| 0.878289614|-1.27205617|
## +-----------------+---+---+----+----------+------------+-----------+
## |leak             |No |335|Inf | 1.9425030|-0.331357136|-2.43426292|
## |                 |Yes|194|Inf | 3.6323091| 0.571786324|-1.31686585|
## +-----------------+---+---+----+----------+------------+-----------+
## |garbage          |No |348|Inf | 2.1288750|-0.207639365|-2.22303246|
## |                 |Yes|181|Inf | 2.8390785| 0.391671786|-1.46407206|
## +-----------------+---+---+----+----------+------------+-----------+
## |crack            |No |440|Inf | 2.1477095|-0.358331030|-2.65129738|
## |                 |Yes| 89|Inf | 4.4773368| 2.627081139|-0.24846136|
## +-----------------+---+---+----+----------+------------+-----------+
## |leaning_wall     |No |500|Inf | 2.2657445|-0.112117298|-2.11133491|
## |                 |Yes| 29|Inf |       Inf| 3.332204510|-0.06899287|
## +-----------------+---+---+----+----------+------------+-----------+
## |scars            |No |325|Inf | 1.7774735|-1.348266966|-4.38514676|
## |                 |Yes|204|Inf |       Inf| 3.337293580|-0.78275934|
## +-----------------+---+---+----+----------+------------+-----------+
## |downward_floor   |No |461|Inf | 2.1757184|-0.292745374|-2.30020130|
## |                 |Yes| 68|Inf |       Inf| 4.204692619|-0.47957308|
## +-----------------+---+---+----+----------+------------+-----------+
## |tilted           |No |427|Inf | 2.0900237|-0.442687819|-2.51314986|
## |                 |Yes|102|Inf |       Inf| 2.965273066|-0.60613580|
## +-----------------+---+---+----+----------+------------+-----------+
## |septic_tank      |No |524|Inf | 2.3173689|-0.007633625|-1.93721444|
## |                 |Yes|  5|Inf |       Inf| 0.405465108|-0.40546511|
## +-----------------+---+---+----+----------+------------+-----------+
## |conc_rainfall    |No | 18|Inf |-0.2231436|-2.833213344|       -Inf|
## |                 |Yes|511|Inf | 2.5502894| 0.058725286|-1.87406206|
## +-----------------+---+---+----+----------+------------+-----------+
## |wastewater       |No |200|Inf | 1.6582281|-0.468378934|-2.75153531|
## |                 |Yes|329|Inf | 3.0413428| 0.275281559|-1.58412010|
## +-----------------+---+---+----+----------+------------+-----------+
## |ground_veg       |No |154|Inf | 1.2992830|-1.378197151|-2.77950917|
## |                 |Yes|375|Inf | 3.2498206| 0.495211396|-1.67820477|
## +-----------------+---+---+----+----------+------------+-----------+
## |angle            |C  | 35|Inf |       Inf|-0.405465108|-3.52636052|
## |                 |D  |128|Inf | 4.1431347| 1.140723774|-1.22782402|
## |                 |E  |366|Inf | 1.9647786|-0.330854244|-2.15542745|
## +-----------------+---+---+----+----------+------------+-----------+
## |TC_saprolite_soil|No |445|Inf | 2.2352520|-0.103462982|-2.02256589|
## |                 |Yes| 84|Inf | 2.9957323| 0.536304709|-1.44691898|
## +-----------------+---+---+----+----------+------------+-----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.91389034|
## +-----------------+---+---+----+----------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)

Equation 2

  • parameters okay and so/so
  • porportion
  • excluded TC_geol_desf

f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)

      stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
                  
                 data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))








p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                              Value Std. Error     t value      p value
## brickTRUE             -0.576068918  0.5134422 -1.12197431 1.309367e-01
## woodTRUE               0.792675332  0.3622551  2.18816907 1.432864e-02
## ENTRUE                 0.681755803  0.3980095  1.71291339 4.336424e-02
## TC_mature_soilTRUE     0.781258113  0.2385243  3.27538130 5.275972e-04
## T_constructionTRUE     0.443038723  0.3772575  1.17436705 1.201240e-01
## landfillTRUE          -0.007528393  0.3346901 -0.02249362 4.910271e-01
## leakTRUE              -0.204661794  0.2345357 -0.87262537 1.914337e-01
## garbageTRUE           -0.204490873  0.3038862 -0.67291929 2.504993e-01
## crackTRUE              1.929647273  0.3327594  5.79892633 3.337042e-09
## leaning_wallTRUE       1.528083306  0.5512235  2.77216668 2.784226e-03
## treeTRUE              -0.141179030  0.2475259 -0.57036070 2.842165e-01
## downward_floorTRUE     1.002041679  0.3597204  2.78561232 2.671336e-03
## tiltedTRUE             1.060599502  0.3124311  3.39466665 3.435610e-04
## ground_vegTRUE         0.782113227  0.2795815  2.79744246 2.575447e-03
## scarsTRUE              3.816548792  0.3741981 10.19927222 9.988188e-25
## mixedTRUE             -0.202299358  0.5022234 -0.40280751 3.435449e-01
## conc_rainfallTRUE      1.133438458  0.5672784  1.99802854 2.285678e-02
## wastewaterTRUE         0.608783886  0.2438119  2.49694072 6.263495e-03
## angleD                 0.739545136  0.4626426  1.59852382 5.496322e-02
## angleE                 1.099510663  0.5417356  2.02960768 2.119822e-02
## bananaTRUE             0.545338039  0.2546905  2.14117947 1.612978e-02
## drainage.L             1.079929448  0.2878552  3.75164167 8.784022e-05
## drainage.Q            -0.072325121  0.1881897 -0.38432039 3.503705e-01
## TC_saprolite_soilTRUE  0.310772313  0.3040231  1.02219957 1.533432e-01
## TCTRUE                -0.801912872  0.5262570 -1.52380467 6.377876e-02
## deforestationTRUE      0.583959860  0.4344756  1.34405673 8.946502e-02
## R1|R2                  0.228779981  1.1150517  0.20517433 4.187180e-01
## R2|R3                  4.687203262  1.1392545  4.11427224 1.942014e-05
## R3|R4                  9.988986057  1.2425872  8.03886104 4.533867e-16
stargazer((ctable), type="text", style="default", digits=2)
## 
## ======================================================
##                       Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE             -0.58    0.51     -1.12   0.13  
## woodTRUE              0.79     0.36     2.19    0.01  
## ENTRUE                0.68     0.40     1.71    0.04  
## TC_mature_soilTRUE    0.78     0.24     3.28    0.001 
## T_constructionTRUE    0.44     0.38     1.17    0.12  
## landfillTRUE          -0.01    0.33     -0.02   0.49  
## leakTRUE              -0.20    0.23     -0.87   0.19  
## garbageTRUE           -0.20    0.30     -0.67   0.25  
## crackTRUE             1.93     0.33     5.80      0   
## leaning_wallTRUE      1.53     0.55     2.77    0.003 
## treeTRUE              -0.14    0.25     -0.57   0.28  
## downward_floorTRUE    1.00     0.36     2.79    0.003 
## tiltedTRUE            1.06     0.31     3.39   0.0003 
## ground_vegTRUE        0.78     0.28     2.80    0.003 
## scarsTRUE             3.82     0.37     10.20     0   
## mixedTRUE             -0.20    0.50     -0.40   0.34  
## conc_rainfallTRUE     1.13     0.57     2.00    0.02  
## wastewaterTRUE        0.61     0.24     2.50    0.01  
## angleD                0.74     0.46     1.60    0.05  
## angleE                1.10     0.54     2.03    0.02  
## bananaTRUE            0.55     0.25     2.14    0.02  
## drainage.L            1.08     0.29     3.75   0.0001 
## drainage.Q            -0.07    0.19     -0.38   0.35  
## TC_saprolite_soilTRUE 0.31     0.30     1.02    0.15  
## TCTRUE                -0.80    0.53     -1.52   0.06  
## deforestationTRUE     0.58     0.43     1.34    0.09  
## R1| R2                0.23     1.12     0.21    0.42  
## R2| R3                4.69     1.14     4.11   0.0000 
## R3| R4                9.99     1.24     8.04      0   
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+-----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4       |
## +-----------------+---+---+----+----------+------------+-----------+
## |brick            |No | 37|Inf | 2.8622009| 1.287854288|-0.86020127|
## |                 |Yes|492|Inf | 2.2958961|-0.089490571|-2.03229476|
## +-----------------+---+---+----+----------+------------+-----------+
## |wood             |No |455|Inf | 2.2344036|-0.171850257|-2.25982323|
## |                 |Yes| 74|Inf | 3.1640676| 1.134979933|-0.67294447|
## +-----------------+---+---+----+----------+------------+-----------+
## |EN               |No |343|Inf | 1.8402119|-0.518607764|-2.38209716|
## |                 |Yes|186|Inf |       Inf| 1.000631880|-1.32687094|
## +-----------------+---+---+----+----------+------------+-----------+
## |TC_mature_soil   |No |252|Inf | 1.8245493|-0.287682072|-2.25129180|
## |                 |Yes|277|Inf | 3.0948232| 0.254065462|-1.66684882|
## +-----------------+---+---+----+----------+------------+-----------+
## |T_construction   |No |207|Inf | 1.5581446|-0.896088025|-2.98061864|
## |                 |Yes|322|Inf | 3.3418976| 0.547435369|-1.51550609|
## +-----------------+---+---+----+----------+------------+-----------+
## |landfill         |No |328|Inf | 1.8387844|-0.523855124|-2.53897387|
## |                 |Yes|201|Inf | 4.6001576| 0.878289614|-1.27205617|
## +-----------------+---+---+----+----------+------------+-----------+
## |leak             |No |335|Inf | 1.9425030|-0.331357136|-2.43426292|
## |                 |Yes|194|Inf | 3.6323091| 0.571786324|-1.31686585|
## +-----------------+---+---+----+----------+------------+-----------+
## |garbage          |No |348|Inf | 2.1288750|-0.207639365|-2.22303246|
## |                 |Yes|181|Inf | 2.8390785| 0.391671786|-1.46407206|
## +-----------------+---+---+----+----------+------------+-----------+
## |crack            |No |440|Inf | 2.1477095|-0.358331030|-2.65129738|
## |                 |Yes| 89|Inf | 4.4773368| 2.627081139|-0.24846136|
## +-----------------+---+---+----+----------+------------+-----------+
## |leaning_wall     |No |500|Inf | 2.2657445|-0.112117298|-2.11133491|
## |                 |Yes| 29|Inf |       Inf| 3.332204510|-0.06899287|
## +-----------------+---+---+----+----------+------------+-----------+
## |tree             |No |202|Inf | 1.5976035|-0.678332095|-2.00372972|
## |                 |Yes|327|Inf | 3.1844436| 0.402917336|-1.86125726|
## +-----------------+---+---+----+----------+------------+-----------+
## |downward_floor   |No |461|Inf | 2.1757184|-0.292745374|-2.30020130|
## |                 |Yes| 68|Inf |       Inf| 4.204692619|-0.47957308|
## +-----------------+---+---+----+----------+------------+-----------+
## |tilted           |No |427|Inf | 2.0900237|-0.442687819|-2.51314986|
## |                 |Yes|102|Inf |       Inf| 2.965273066|-0.60613580|
## +-----------------+---+---+----+----------+------------+-----------+
## |ground_veg       |No |154|Inf | 1.2992830|-1.378197151|-2.77950917|
## |                 |Yes|375|Inf | 3.2498206| 0.495211396|-1.67820477|
## +-----------------+---+---+----+----------+------------+-----------+
## |scars            |No |325|Inf | 1.7774735|-1.348266966|-4.38514676|
## |                 |Yes|204|Inf |       Inf| 3.337293580|-0.78275934|
## +-----------------+---+---+----+----------+------------+-----------+
## |mixed            |No |488|Inf | 2.2869073|-0.098440073|-2.04307390|
## |                 |Yes| 41|Inf | 2.9704145| 1.268511325|-0.88238918|
## +-----------------+---+---+----+----------+------------+-----------+
## |conc_rainfall    |No | 18|Inf |-0.2231436|-2.833213344|       -Inf|
## |                 |Yes|511|Inf | 2.5502894| 0.058725286|-1.87406206|
## +-----------------+---+---+----+----------+------------+-----------+
## |wastewater       |No |200|Inf | 1.6582281|-0.468378934|-2.75153531|
## |                 |Yes|329|Inf | 3.0413428| 0.275281559|-1.58412010|
## +-----------------+---+---+----+----------+------------+-----------+
## |angle            |C  | 35|Inf |       Inf|-0.405465108|-3.52636052|
## |                 |D  |128|Inf | 4.1431347| 1.140723774|-1.22782402|
## |                 |E  |366|Inf | 1.9647786|-0.330854244|-2.15542745|
## +-----------------+---+---+----+----------+------------+-----------+
## |banana           |No |354|Inf | 1.9266788|-0.412532275|-2.14798386|
## |                 |Yes|175|Inf | 4.4601444| 0.860940637|-1.53582610|
## +-----------------+---+---+----+----------+------------+-----------+
## |drainage         |Y  | 63|Inf | 0.8397507|-1.927891644|       -Inf|
## |                 |P  |242|Inf | 2.3536403|-0.541801552|-2.58288706|
## |                 |N  |224|Inf | 3.4339872| 1.074942545|-1.22146596|
## +-----------------+---+---+----+----------+------------+-----------+
## |TC_saprolite_soil|No |445|Inf | 2.2352520|-0.103462982|-2.02256589|
## |                 |Yes| 84|Inf | 2.9957323| 0.536304709|-1.44691898|
## +-----------------+---+---+----+----------+------------+-----------+
## |TC               |No | 28|Inf |       Inf| 1.299282984|-1.29928298|
## |                 |Yes|501|Inf | 2.2679496|-0.067890336|-1.95736503|
## +-----------------+---+---+----+----------+------------+-----------+
## |deforestation    |No |497|Inf | 2.3826278| 0.052325819|-1.89403832|
## |                 |Yes| 32|Inf | 1.6863990|-0.938269639|-2.26868354|
## +-----------------+---+---+----+----------+------------+-----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.91389034|
## +-----------------+---+---+----+----------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)

Equation 3

  • parameters okay and so/so
  • porportion
  • p-value based equation 2 > 0.5

f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)

# x=TRUE, y=TRUE used by resid() below 

eq_OLR_03 <- polr(risk ~ wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))


p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                         Value Std. Error    t value      p value
## woodTRUE            0.8472829  0.3365490  2.5175621 5.908507e-03
## TC_mature_soilTRUE  0.6578579  0.2242972  2.9329743 1.678658e-03
## T_constructionTRUE  0.2597627  0.2942704  0.8827347 1.886898e-01
## landfillTRUE        0.1537936  0.2913467  0.5278714 2.987943e-01
## crackTRUE           1.9633741  0.3216934  6.1032473 5.196743e-10
## leaning_wallTRUE    1.5218562  0.5391654  2.8226146 2.381690e-03
## treeTRUE           -0.1048324  0.2347933 -0.4464880 3.276224e-01
## downward_floorTRUE  0.9665673  0.3486718  2.7721405 2.784450e-03
## tiltedTRUE          1.0913213  0.3066097  3.5593176 1.859098e-04
## ground_vegTRUE      0.7964582  0.2691167  2.9595276 1.540556e-03
## scarsTRUE           3.7348373  0.3649582 10.2336034 7.010172e-25
## conc_rainfallTRUE   1.1262103  0.5592657  2.0137303 2.201893e-02
## wastewaterTRUE      0.5329160  0.2368840  2.2496923 1.223424e-02
## bananaTRUE          0.4893149  0.2444585  2.0016271 2.266243e-02
## drainage.L          1.0745434  0.2817741  3.8134922 6.850842e-05
## drainage.Q         -0.0649265  0.1860581 -0.3489583 3.635603e-01
## R1|R2               0.4026038  0.5439136  0.7401981 2.295899e-01
## R2|R3               4.7219849  0.6060464  7.7914574 3.312032e-15
## R3|R4               9.8884182  0.7605271 13.0020581 5.954725e-39
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           0.85     0.34     2.52    0.01  
## TC_mature_soilTRUE 0.66     0.22     2.93    0.002 
## T_constructionTRUE 0.26     0.29     0.88    0.19  
## landfillTRUE       0.15     0.29     0.53    0.30  
## crackTRUE          1.96     0.32     6.10      0   
## leaning_wallTRUE   1.52     0.54     2.82    0.002 
## treeTRUE           -0.10    0.23     -0.45   0.33  
## downward_floorTRUE 0.97     0.35     2.77    0.003 
## tiltedTRUE         1.09     0.31     3.56   0.0002 
## ground_vegTRUE     0.80     0.27     2.96    0.002 
## scarsTRUE          3.73     0.36     10.23     0   
## conc_rainfallTRUE  1.13     0.56     2.01    0.02  
## wastewaterTRUE     0.53     0.24     2.25    0.01  
## bananaTRUE         0.49     0.24     2.00    0.02  
## drainage.L         1.07     0.28     3.81   0.0001 
## drainage.Q         -0.06    0.19     -0.35   0.36  
## R1| R2             0.40     0.54     0.74    0.23  
## R2| R3             4.72     0.61     7.79      0   
## R3| R4             9.89     0.76     13.00     0   
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
          data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+-----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4       |
## +--------------+---+---+----+----------+------------+-----------+
## |wood          |No |455|Inf | 2.2344036|-0.171850257|-2.25982323|
## |              |Yes| 74|Inf | 3.1640676| 1.134979933|-0.67294447|
## +--------------+---+---+----+----------+------------+-----------+
## |TC_mature_soil|No |252|Inf | 1.8245493|-0.287682072|-2.25129180|
## |              |Yes|277|Inf | 3.0948232| 0.254065462|-1.66684882|
## +--------------+---+---+----+----------+------------+-----------+
## |T_construction|No |207|Inf | 1.5581446|-0.896088025|-2.98061864|
## |              |Yes|322|Inf | 3.3418976| 0.547435369|-1.51550609|
## +--------------+---+---+----+----------+------------+-----------+
## |landfill      |No |328|Inf | 1.8387844|-0.523855124|-2.53897387|
## |              |Yes|201|Inf | 4.6001576| 0.878289614|-1.27205617|
## +--------------+---+---+----+----------+------------+-----------+
## |crack         |No |440|Inf | 2.1477095|-0.358331030|-2.65129738|
## |              |Yes| 89|Inf | 4.4773368| 2.627081139|-0.24846136|
## +--------------+---+---+----+----------+------------+-----------+
## |leaning_wall  |No |500|Inf | 2.2657445|-0.112117298|-2.11133491|
## |              |Yes| 29|Inf |       Inf| 3.332204510|-0.06899287|
## +--------------+---+---+----+----------+------------+-----------+
## |tree          |No |202|Inf | 1.5976035|-0.678332095|-2.00372972|
## |              |Yes|327|Inf | 3.1844436| 0.402917336|-1.86125726|
## +--------------+---+---+----+----------+------------+-----------+
## |downward_floor|No |461|Inf | 2.1757184|-0.292745374|-2.30020130|
## |              |Yes| 68|Inf |       Inf| 4.204692619|-0.47957308|
## +--------------+---+---+----+----------+------------+-----------+
## |tilted        |No |427|Inf | 2.0900237|-0.442687819|-2.51314986|
## |              |Yes|102|Inf |       Inf| 2.965273066|-0.60613580|
## +--------------+---+---+----+----------+------------+-----------+
## |ground_veg    |No |154|Inf | 1.2992830|-1.378197151|-2.77950917|
## |              |Yes|375|Inf | 3.2498206| 0.495211396|-1.67820477|
## +--------------+---+---+----+----------+------------+-----------+
## |scars         |No |325|Inf | 1.7774735|-1.348266966|-4.38514676|
## |              |Yes|204|Inf |       Inf| 3.337293580|-0.78275934|
## +--------------+---+---+----+----------+------------+-----------+
## |conc_rainfall |No | 18|Inf |-0.2231436|-2.833213344|       -Inf|
## |              |Yes|511|Inf | 2.5502894| 0.058725286|-1.87406206|
## +--------------+---+---+----+----------+------------+-----------+
## |wastewater    |No |200|Inf | 1.6582281|-0.468378934|-2.75153531|
## |              |Yes|329|Inf | 3.0413428| 0.275281559|-1.58412010|
## +--------------+---+---+----+----------+------------+-----------+
## |banana        |No |354|Inf | 1.9266788|-0.412532275|-2.14798386|
## |              |Yes|175|Inf | 4.4601444| 0.860940637|-1.53582610|
## +--------------+---+---+----+----------+------------+-----------+
## |drainage      |Y  | 63|Inf | 0.8397507|-1.927891644|       -Inf|
## |              |P  |242|Inf | 2.3536403|-0.541801552|-2.58288706|
## |              |N  |224|Inf | 3.4339872| 1.074942545|-1.22146596|
## +--------------+---+---+----+----------+------------+-----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.91389034|
## +--------------+---+---+----+----------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)

Equation 4

  • p-value equation 3 > 0.05 (banana, DepTaludeCorte)
  • consider proportion
  • paremeters okay & so/so
  • fashion order

f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)

eq_OLR_04 <- polr(risk~ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
                  , data= train.data
           ,  method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value

ctable <- coef(summary(eq_OLR_04))

ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
##                          Value Std. Error    t value      p value
## woodTRUE            0.85304243  0.3357342  2.5408268 5.908507e-03
## TC_mature_soilTRUE  0.63834225  0.2210786  2.8873996 1.678658e-03
## T_constructionTRUE  0.35590400  0.2312035  1.5393536 1.886898e-01
## crackTRUE           1.97452137  0.3213274  6.1448887 2.987943e-01
## leaning_wallTRUE    1.50670640  0.5398380  2.7910346 5.196743e-10
## treeTRUE           -0.11199255  0.2342792 -0.4780303 2.381690e-03
## downward_floorTRUE  0.98265686  0.3472089  2.8301607 3.276224e-01
## tiltedTRUE          1.10777320  0.3049287  3.6328921 2.784450e-03
## ground_vegTRUE      0.80317466  0.2686610  2.9895465 1.859098e-04
## scarsTRUE           3.73867640  0.3650028 10.2428694 1.540556e-03
## conc_rainfallTRUE   1.13903798  0.5591381  2.0371319 7.010172e-25
## wastewaterTRUE      0.50715668  0.2317873  2.1880264 2.201893e-02
## bananaTRUE          0.49314073  0.2442986  2.0185985 1.223424e-02
## drainage.L          1.08506604  0.2810601  3.8606187 2.266243e-02
## drainage.Q         -0.05871528  0.1856649 -0.3162433 6.850842e-05
## R1|R2               0.39969336  0.5443680  0.7342338 3.635603e-01
## R2|R3               4.72034503  0.6066484  7.7810224 2.295899e-01
## R3|R4               9.88194863  0.7606510 12.9914364 3.312032e-15
stargazer((ctable), type="text", style="default", digits=2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           0.85     0.34     2.54    0.01  
## TC_mature_soilTRUE 0.64     0.22     2.89    0.002 
## T_constructionTRUE 0.36     0.23     1.54    0.19  
## crackTRUE          1.97     0.32     6.14    0.30  
## leaning_wallTRUE   1.51     0.54     2.79      0   
## treeTRUE           -0.11    0.23     -0.48   0.002 
## downward_floorTRUE 0.98     0.35     2.83    0.33  
## tiltedTRUE         1.11     0.30     3.63    0.003 
## ground_vegTRUE     0.80     0.27     2.99   0.0002 
## scarsTRUE          3.74     0.37     10.24   0.002 
## conc_rainfallTRUE  1.14     0.56     2.04      0   
## wastewaterTRUE     0.51     0.23     2.19    0.02  
## bananaTRUE         0.49     0.24     2.02    0.01  
## drainage.L         1.09     0.28     3.86    0.02  
## drainage.Q         -0.06    0.19     -0.32  0.0001 
## R1| R2             0.40     0.54     0.73    0.36  
## R2| R3             4.72     0.61     7.78    0.23  
## R3| R4             9.88     0.76     12.99     0   
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+-----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4       |
## +--------------+---+---+----+----------+------------+-----------+
## |wood          |No |455|Inf | 2.2344036|-0.171850257|-2.25982323|
## |              |Yes| 74|Inf | 3.1640676| 1.134979933|-0.67294447|
## +--------------+---+---+----+----------+------------+-----------+
## |TC_mature_soil|No |252|Inf | 1.8245493|-0.287682072|-2.25129180|
## |              |Yes|277|Inf | 3.0948232| 0.254065462|-1.66684882|
## +--------------+---+---+----+----------+------------+-----------+
## |T_construction|No |207|Inf | 1.5581446|-0.896088025|-2.98061864|
## |              |Yes|322|Inf | 3.3418976| 0.547435369|-1.51550609|
## +--------------+---+---+----+----------+------------+-----------+
## |crack         |No |440|Inf | 2.1477095|-0.358331030|-2.65129738|
## |              |Yes| 89|Inf | 4.4773368| 2.627081139|-0.24846136|
## +--------------+---+---+----+----------+------------+-----------+
## |leaning_wall  |No |500|Inf | 2.2657445|-0.112117298|-2.11133491|
## |              |Yes| 29|Inf |       Inf| 3.332204510|-0.06899287|
## +--------------+---+---+----+----------+------------+-----------+
## |tree          |No |202|Inf | 1.5976035|-0.678332095|-2.00372972|
## |              |Yes|327|Inf | 3.1844436| 0.402917336|-1.86125726|
## +--------------+---+---+----+----------+------------+-----------+
## |downward_floor|No |461|Inf | 2.1757184|-0.292745374|-2.30020130|
## |              |Yes| 68|Inf |       Inf| 4.204692619|-0.47957308|
## +--------------+---+---+----+----------+------------+-----------+
## |tilted        |No |427|Inf | 2.0900237|-0.442687819|-2.51314986|
## |              |Yes|102|Inf |       Inf| 2.965273066|-0.60613580|
## +--------------+---+---+----+----------+------------+-----------+
## |ground_veg    |No |154|Inf | 1.2992830|-1.378197151|-2.77950917|
## |              |Yes|375|Inf | 3.2498206| 0.495211396|-1.67820477|
## +--------------+---+---+----+----------+------------+-----------+
## |scars         |No |325|Inf | 1.7774735|-1.348266966|-4.38514676|
## |              |Yes|204|Inf |       Inf| 3.337293580|-0.78275934|
## +--------------+---+---+----+----------+------------+-----------+
## |conc_rainfall |No | 18|Inf |-0.2231436|-2.833213344|       -Inf|
## |              |Yes|511|Inf | 2.5502894| 0.058725286|-1.87406206|
## +--------------+---+---+----+----------+------------+-----------+
## |wastewater    |No |200|Inf | 1.6582281|-0.468378934|-2.75153531|
## |              |Yes|329|Inf | 3.0413428| 0.275281559|-1.58412010|
## +--------------+---+---+----+----------+------------+-----------+
## |banana        |No |354|Inf | 1.9266788|-0.412532275|-2.14798386|
## |              |Yes|175|Inf | 4.4601444| 0.860940637|-1.53582610|
## +--------------+---+---+----+----------+------------+-----------+
## |drainage      |Y  | 63|Inf | 0.8397507|-1.927891644|       -Inf|
## |              |P  |242|Inf | 2.3536403|-0.541801552|-2.58288706|
## |              |N  |224|Inf | 3.4339872| 1.074942545|-1.22146596|
## +--------------+---+---+----+----------+------------+-----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.91389034|
## +--------------+---+---+----+----------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Equation 5 - Based on Equation 1

  • based on Eq 1
  • less p-value > 0.10 (
# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_05 <- polr(risk ~ brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_05))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                         Value Std. Error    t value      p value
## brickTRUE          -0.4663079  0.4333423 -1.0760731 1.409473e-01
## woodTRUE            0.9850586  0.3324115  2.9633711 1.521448e-03
## TC_mature_soilTRUE  0.6897894  0.2183751  3.1587360 7.922747e-04
## T_constructionTRUE  0.3517280  0.2277103  1.5446293 6.121798e-02
## crackTRUE           1.8780415  0.3156374  5.9499966 1.340740e-09
## leaning_wallTRUE    1.4451512  0.5244969  2.7553091 2.931836e-03
## scarsTRUE           3.7587610  0.3601930 10.4354095 8.543773e-26
## downward_floorTRUE  1.2206262  0.3424535  3.5643557 1.823755e-04
## tiltedTRUE          1.2102256  0.3047335  3.9714235 3.572223e-05
## conc_rainfallTRUE   1.5644230  0.5282199  2.9616890 1.529783e-03
## wastewaterTRUE      0.7026601  0.2252087  3.1200400 9.041323e-04
## ground_vegTRUE      1.1032074  0.2433719  4.5330108 2.907441e-06
## R1|R2               0.6278189  0.6729307  0.9329622 1.754197e-01
## R2|R3               4.7586091  0.7320817  6.5001066 4.013157e-11
## R3|R4               9.8146315  0.8511334 11.5312492 4.590097e-31
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -0.47    0.43     -1.08   0.14  
## woodTRUE           0.99     0.33     2.96    0.002 
## TC_mature_soilTRUE 0.69     0.22     3.16    0.001 
## T_constructionTRUE 0.35     0.23     1.54    0.06  
## crackTRUE          1.88     0.32     5.95      0   
## leaning_wallTRUE   1.45     0.52     2.76    0.003 
## scarsTRUE          3.76     0.36     10.44     0   
## downward_floorTRUE 1.22     0.34     3.56   0.0002 
## tiltedTRUE         1.21     0.30     3.97   0.0000 
## conc_rainfallTRUE  1.56     0.53     2.96    0.002 
## wastewaterTRUE     0.70     0.23     3.12    0.001 
## ground_vegTRUE     1.10     0.24     4.53   0.0000 
## R1| R2             0.63     0.67     0.93    0.18  
## R2| R3             4.76     0.73     6.50      0   
## R3| R4             9.81     0.85     11.53     0   
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~  brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+-----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4       |
## +--------------+---+---+----+----------+------------+-----------+
## |brick         |No | 37|Inf | 2.8622009| 1.287854288|-0.86020127|
## |              |Yes|492|Inf | 2.2958961|-0.089490571|-2.03229476|
## +--------------+---+---+----+----------+------------+-----------+
## |wood          |No |455|Inf | 2.2344036|-0.171850257|-2.25982323|
## |              |Yes| 74|Inf | 3.1640676| 1.134979933|-0.67294447|
## +--------------+---+---+----+----------+------------+-----------+
## |TC_mature_soil|No |252|Inf | 1.8245493|-0.287682072|-2.25129180|
## |              |Yes|277|Inf | 3.0948232| 0.254065462|-1.66684882|
## +--------------+---+---+----+----------+------------+-----------+
## |T_construction|No |207|Inf | 1.5581446|-0.896088025|-2.98061864|
## |              |Yes|322|Inf | 3.3418976| 0.547435369|-1.51550609|
## +--------------+---+---+----+----------+------------+-----------+
## |crack         |No |440|Inf | 2.1477095|-0.358331030|-2.65129738|
## |              |Yes| 89|Inf | 4.4773368| 2.627081139|-0.24846136|
## +--------------+---+---+----+----------+------------+-----------+
## |leaning_wall  |No |500|Inf | 2.2657445|-0.112117298|-2.11133491|
## |              |Yes| 29|Inf |       Inf| 3.332204510|-0.06899287|
## +--------------+---+---+----+----------+------------+-----------+
## |scars         |No |325|Inf | 1.7774735|-1.348266966|-4.38514676|
## |              |Yes|204|Inf |       Inf| 3.337293580|-0.78275934|
## +--------------+---+---+----+----------+------------+-----------+
## |downward_floor|No |461|Inf | 2.1757184|-0.292745374|-2.30020130|
## |              |Yes| 68|Inf |       Inf| 4.204692619|-0.47957308|
## +--------------+---+---+----+----------+------------+-----------+
## |tilted        |No |427|Inf | 2.0900237|-0.442687819|-2.51314986|
## |              |Yes|102|Inf |       Inf| 2.965273066|-0.60613580|
## +--------------+---+---+----+----------+------------+-----------+
## |conc_rainfall |No | 18|Inf |-0.2231436|-2.833213344|       -Inf|
## |              |Yes|511|Inf | 2.5502894| 0.058725286|-1.87406206|
## +--------------+---+---+----+----------+------------+-----------+
## |wastewater    |No |200|Inf | 1.6582281|-0.468378934|-2.75153531|
## |              |Yes|329|Inf | 3.0413428| 0.275281559|-1.58412010|
## +--------------+---+---+----+----------+------------+-----------+
## |ground_veg    |No |154|Inf | 1.2992830|-1.378197151|-2.77950917|
## |              |Yes|375|Inf | 3.2498206| 0.495211396|-1.67820477|
## +--------------+---+---+----+----------+------------+-----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.91389034|
## +--------------+---+---+----+----------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

OLR Equation 6

# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_06))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                          Value Std. Error    t value      p value
## brickTRUE          -0.83120598  0.5027061 -1.6534632 4.911831e-02
## woodTRUE            0.67020425  0.3356198  1.9969151 2.291720e-02
## mixedTRUE           0.07836333  0.4876315  0.1607019 4.361641e-01
## ENTRUE              0.79586319  0.3841495  2.0717537 1.914421e-02
## TCTRUE             -0.20305150  0.4840658 -0.4194708 3.374360e-01
## T_constructionTRUE  0.41457210  0.3568609  1.1617191 1.226748e-01
## landfillTRUE        0.10079726  0.3176051  0.3173666 3.754827e-01
## leakTRUE            0.03402706  0.2241660  0.1517940 4.396747e-01
## garbageTRUE        -0.15745163  0.2902313 -0.5425040 2.937357e-01
## crackTRUE           1.80766442  0.3218568  5.6163624 9.750971e-09
## leaning_wallTRUE    1.59519693  0.5426455  2.9396666 1.642828e-03
## treeTRUE           -0.03760797  0.2379203 -0.1580696 4.372010e-01
## tiltedTRUE          1.19939706  0.3025243  3.9646305 3.675486e-05
## angleD              0.91536705  0.4529054  2.0211000 2.163470e-02
## angleE              1.32016273  0.5256055  2.5116991 6.007575e-03
## ground_vegTRUE      0.91560884  0.2668482  3.4311979 3.004610e-04
## scarsTRUE           3.80782628  0.3622567 10.5114022 3.827343e-26
## conc_rainfallTRUE   1.86737874  0.5363913  3.4813741 2.494241e-04
## wastewaterTRUE      0.68747410  0.2310714  2.9751591 1.464183e-03
## bananaTRUE          0.61047150  0.2469771  2.4717733 6.722236e-03
## R1|R2               1.36769846  1.0595163  1.2908707 9.837426e-02
## R2|R3               5.46340185  1.0971120  4.9798034 3.182445e-07
## R3|R4              10.47691152  1.2002344  8.7290543 1.284055e-18
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -0.83    0.50     -1.65   0.05  
## woodTRUE           0.67     0.34     2.00    0.02  
## mixedTRUE          0.08     0.49     0.16    0.44  
## ENTRUE             0.80     0.38     2.07    0.02  
## TCTRUE             -0.20    0.48     -0.42   0.34  
## T_constructionTRUE 0.41     0.36     1.16    0.12  
## landfillTRUE       0.10     0.32     0.32    0.38  
## leakTRUE           0.03     0.22     0.15    0.44  
## garbageTRUE        -0.16    0.29     -0.54   0.29  
## crackTRUE          1.81     0.32     5.62      0   
## leaning_wallTRUE   1.60     0.54     2.94    0.002 
## treeTRUE           -0.04    0.24     -0.16   0.44  
## tiltedTRUE         1.20     0.30     3.96   0.0000 
## angleD             0.92     0.45     2.02    0.02  
## angleE             1.32     0.53     2.51    0.01  
## ground_vegTRUE     0.92     0.27     3.43   0.0003 
## scarsTRUE          3.81     0.36     10.51     0   
## conc_rainfallTRUE  1.87     0.54     3.48   0.0002 
## wastewaterTRUE     0.69     0.23     2.98    0.001 
## bananaTRUE         0.61     0.25     2.47    0.01  
## R1| R2             1.37     1.06     1.29    0.10  
## R2| R3             5.46     1.10     4.98   0.0000 
## R3| R4             10.48    1.20     8.73      0   
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~  brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+-----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4       |
## +--------------+---+---+----+----------+------------+-----------+
## |brick         |No | 37|Inf | 2.8622009| 1.287854288|-0.86020127|
## |              |Yes|492|Inf | 2.2958961|-0.089490571|-2.03229476|
## +--------------+---+---+----+----------+------------+-----------+
## |wood          |No |455|Inf | 2.2344036|-0.171850257|-2.25982323|
## |              |Yes| 74|Inf | 3.1640676| 1.134979933|-0.67294447|
## +--------------+---+---+----+----------+------------+-----------+
## |mixed         |No |488|Inf | 2.2869073|-0.098440073|-2.04307390|
## |              |Yes| 41|Inf | 2.9704145| 1.268511325|-0.88238918|
## +--------------+---+---+----+----------+------------+-----------+
## |EN            |No |343|Inf | 1.8402119|-0.518607764|-2.38209716|
## |              |Yes|186|Inf |       Inf| 1.000631880|-1.32687094|
## +--------------+---+---+----+----------+------------+-----------+
## |TC            |No | 28|Inf |       Inf| 1.299282984|-1.29928298|
## |              |Yes|501|Inf | 2.2679496|-0.067890336|-1.95736503|
## +--------------+---+---+----+----------+------------+-----------+
## |T_construction|No |207|Inf | 1.5581446|-0.896088025|-2.98061864|
## |              |Yes|322|Inf | 3.3418976| 0.547435369|-1.51550609|
## +--------------+---+---+----+----------+------------+-----------+
## |landfill      |No |328|Inf | 1.8387844|-0.523855124|-2.53897387|
## |              |Yes|201|Inf | 4.6001576| 0.878289614|-1.27205617|
## +--------------+---+---+----+----------+------------+-----------+
## |leak          |No |335|Inf | 1.9425030|-0.331357136|-2.43426292|
## |              |Yes|194|Inf | 3.6323091| 0.571786324|-1.31686585|
## +--------------+---+---+----+----------+------------+-----------+
## |garbage       |No |348|Inf | 2.1288750|-0.207639365|-2.22303246|
## |              |Yes|181|Inf | 2.8390785| 0.391671786|-1.46407206|
## +--------------+---+---+----+----------+------------+-----------+
## |crack         |No |440|Inf | 2.1477095|-0.358331030|-2.65129738|
## |              |Yes| 89|Inf | 4.4773368| 2.627081139|-0.24846136|
## +--------------+---+---+----+----------+------------+-----------+
## |leaning_wall  |No |500|Inf | 2.2657445|-0.112117298|-2.11133491|
## |              |Yes| 29|Inf |       Inf| 3.332204510|-0.06899287|
## +--------------+---+---+----+----------+------------+-----------+
## |tree          |No |202|Inf | 1.5976035|-0.678332095|-2.00372972|
## |              |Yes|327|Inf | 3.1844436| 0.402917336|-1.86125726|
## +--------------+---+---+----+----------+------------+-----------+
## |tilted        |No |427|Inf | 2.0900237|-0.442687819|-2.51314986|
## |              |Yes|102|Inf |       Inf| 2.965273066|-0.60613580|
## +--------------+---+---+----+----------+------------+-----------+
## |angle         |C  | 35|Inf |       Inf|-0.405465108|-3.52636052|
## |              |D  |128|Inf | 4.1431347| 1.140723774|-1.22782402|
## |              |E  |366|Inf | 1.9647786|-0.330854244|-2.15542745|
## +--------------+---+---+----+----------+------------+-----------+
## |ground_veg    |No |154|Inf | 1.2992830|-1.378197151|-2.77950917|
## |              |Yes|375|Inf | 3.2498206| 0.495211396|-1.67820477|
## +--------------+---+---+----+----------+------------+-----------+
## |scars         |No |325|Inf | 1.7774735|-1.348266966|-4.38514676|
## |              |Yes|204|Inf |       Inf| 3.337293580|-0.78275934|
## +--------------+---+---+----+----------+------------+-----------+
## |conc_rainfall |No | 18|Inf |-0.2231436|-2.833213344|       -Inf|
## |              |Yes|511|Inf | 2.5502894| 0.058725286|-1.87406206|
## +--------------+---+---+----+----------+------------+-----------+
## |wastewater    |No |200|Inf | 1.6582281|-0.468378934|-2.75153531|
## |              |Yes|329|Inf | 3.0413428| 0.275281559|-1.58412010|
## +--------------+---+---+----+----------+------------+-----------+
## |banana        |No |354|Inf | 1.9266788|-0.412532275|-2.14798386|
## |              |Yes|175|Inf | 4.4601444| 0.860940637|-1.53582610|
## +--------------+---+---+----+----------+------------+-----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.91389034|
## +--------------+---+---+----+----------+------------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Predicion on test data Eq 1: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_01, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
##     predictedLevel1
##      R1 R2 R3 R4
##   R1  3 14  2  0
##   R2  3 82  8  0
##   R3  0 13 66  5
##   R4  0  0 13 15
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1 
## [1] 0.2589286

Predicion on test data Eq 2: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
##     predictedLevel2
##      R1 R2 R3 R4
##   R1  6 11  2  0
##   R2  3 81  9  0
##   R3  0 10 67  7
##   R4  0  0 14 14
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.25

Predicion on test data Eq 3: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_03, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
##     predictedLevel3
##      R1 R2 R3 R4
##   R1  6 11  2  0
##   R2  4 82  7  0
##   R3  0 12 66  6
##   R4  0  0 13 15
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.2455357

Predicion on test data Eq 4: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_04, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
##     predictedLevel4
##      R1 R2 R3 R4
##   R1  6 11  2  0
##   R2  4 81  8  0
##   R3  0 12 66  6
##   R4  0  0 14 14
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.2544643

Predicion on test data Eq 5: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly

predictedScores5 <- predict(eq_OLR_05, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
##     predictedLevel5
##      R1 R2 R3 R4
##   R1  3 14  2  0
##   R2  2 84  7  0
##   R3  0 15 65  4
##   R4  0  0 14 14
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.2589286

Predicion on test data Eq 6: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly

predictedScores6 <- predict(eq_OLR_06, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
##     predictedLevel6
##      R1 R2 R3 R4
##   R1  4 13  2  0
##   R2  1 84  8  0
##   R3  0 17 60  7
##   R4  0  0 13 15
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.2723214

Predicion on test data Eq 7: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

#Table 

df2 <- data.frame(
  
  "Equations"=c(1:6), 
  "Predicted"=c(1-p1, 
                1-p2,
                1-p3,
                1-p4,
                1-p5,
                1-p6
               
              
    
    
  )
  
  
  
)

df2
##   Equations Predicted
## 1         1 0.7410714
## 2         2 0.7500000
## 3         3 0.7544643
## 4         4 0.7455357
## 5         5 0.7410714
## 6         6 0.7276786